//
// Created by ECNU on 2024/2/22.
//
#include <nanofaiss/utils/distances.h>

#include <nanofaiss/impl/platform_macros.h>

#include <algorithm>


namespace faiss {

FAISS_PRAGMA_IMPRECISE_FUNCTION_BEGIN
float fvec_norm_L2sqr(const float *x, size_t d) {
    float res = 0.F;
    FAISS_PRAGMA_IMPRECISE_LOOP
    for (size_t i = 0; i != d; ++i)
        res += x[i] * x[i];
    return res;
}
FAISS_PRAGMA_IMPRECISE_FUNCTION_END


FAISS_PRAGMA_IMPRECISE_FUNCTION_BEGIN
float fvec_L2sqr(const float *x, const float *y, size_t d) {
    size_t i;
    float res = 0;
    FAISS_PRAGMA_IMPRECISE_LOOP
    for (i = 0; i != d; i++)
        res += (x[i] - y[i]) * (x[i] - y[i]);
    return res;
}

FAISS_PRAGMA_IMPRECISE_FUNCTION_END

}
